package com.richapp.launcher.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

/**
 * Created by wangwei on 2017/4/9.
 * 读取application 标签下的meta value
 */

public class MetaUtil {

    public static void init(Context context) {
        ApplicationInfo info = getApplicationInfo(context);
        if (info != null) {
            SharePrefenceUtil.setStringValue(context,  info.metaData.getString(SharePrefenceUtil.SHARE_PM25_TOKEN),SharePrefenceUtil.SHARE_PM25_TOKEN);

            SharePrefenceUtil.setStringValue(context,  info.metaData.getString(SharePrefenceUtil.SHARE_IP_LOCATION_TOKEN),SharePrefenceUtil.SHARE_IP_LOCATION_TOKEN);
            SharePrefenceUtil.setStringValue(context,  info.metaData.getString(SharePrefenceUtil.SHARE_WHEATHER_TOKEN),SharePrefenceUtil.SHARE_WHEATHER_TOKEN);
        }
    }

    public static ApplicationInfo getApplicationInfo(Context context) {
        ApplicationInfo applicationInfo = null;
        try {
            applicationInfo = context.getPackageManager()
                    .getApplicationInfo(context.getPackageName(),
                            PackageManager.GET_META_DATA);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return applicationInfo;
    }
}
